//
//  XMUserModel.m
//  XunMi
//
//  Created by MacBook on 2024/2/19.
//  Copyright © 2024 TieZhu. All rights reserved.
//

#import "XMUserModel.h"

@implementation XMUserModel

- (NSString *)showName {
    if ([XMUtil isBlankString:self.alias]) {
        return self.nickname;
    }
    return self.alias;
}

- (UIColor *)showColor {
    if ([XMUtil isBlankString:self.member_time]) {
        return k1F1F1F;
    }
    return kMemberNameColor;
}

+ (NSDictionary *)mj_replacedKeyFromPropertyName {
    return @{@"tags": @"label"};
}

+ (NSDictionary *)mj_objectClassInArray {
    return @{
        @"avatar": @"XMFileModel",
        @"voice_intro": @"XMFileModel",
        @"video_cover": @"XMFileModel",
        @"album_list": @"XMRecentPhotosModel",
    };
}
// 当字典转模型完毕时调用
- (void)mj_didConvertToObjectWithKeyValues:(NSDictionary *)keyValues {
    
}

#pragma mark - 辅助相关
#pragma mark - 状态
- (BOOL)isMan {
    return self.gender.intValue == 1;
}

- (BOOL)isGirl {
    return self.gender.intValue == 2;
}


- (CGFloat)userDetailCellHeightWithIndex:(NSInteger)index {
    switch (index) {
        case 0:
            return kScreenWidth + 46;
            break;
        case 1:
            return 135 - 56 + (self.alias.length == 0 ? 0 : 15) + (self.dynamic_list.count == 0 ? 0 : 56);
            break;
        case 2:
            return [self tagsCellHeightWithArray:self.tags] + 30;
            break;
        case 3:
            return [self.introduce heightForFont:kUIFont(12) width:kScreenWidth - 40] + 115;
            break;
        case 4:
            return self.album_list.count == 0 ? 0 : 320;
            break;
        default:
            return 0;
            break;
    }
}
- (CGFloat)tagsCellHeightWithArray:(NSArray *)tagsArray {
    if (tagsArray.count == 0) {
        return 0;
    }
    CGFloat leftMarginLabel = 20;
    CGFloat topMarginLabel = 0;
    CGFloat horizontalSpace = 5;
    CGFloat verticalSpace = 5;
    CGFloat labelHeight = 20;
    CGFloat windthMax = kScreenWidth - leftMarginLabel * 2;
    CGFloat labelMinX = leftMarginLabel;
    CGFloat labelMimY = topMarginLabel;
    CGFloat lastLabelMaxY = topMarginLabel;
    for (int i = 0; i < tagsArray.count; i++) {
        NSString *tagStr = tagsArray[i];
        UIButton *labelButton = [UIButton buttonWithType:UIButtonTypeCustom];
        CGFloat labelWidth = [tagStr widthForFont:kUIFont(12)] + 24;
        labelWidth = labelWidth < 47 ? 47 : labelWidth;
        labelButton.frame = CGRectMake(labelMinX, labelMimY, labelWidth, labelHeight);
        if (labelMinX + labelWidth + horizontalSpace > windthMax) {
            labelMinX = leftMarginLabel;
            labelMimY = labelMimY + labelButton.frame.size.height + verticalSpace;
            labelButton.frame = CGRectMake(labelMinX, labelMimY, labelWidth, labelHeight);
        }
        labelMinX = labelButton.frame.size.width + labelButton.frame.origin.x + horizontalSpace;
        if (i == tagsArray.count - 1) {
            lastLabelMaxY = labelButton.frame.origin.y;
        }
    }
    return lastLabelMaxY + labelHeight + 10;
}

@end


@implementation XMFileModel

    

@end
